package com.example.addressbook.dao;

import com.example.addressbook.dto.linkmanInfo;
import com.example.addressbook.entities.Grouping;
import com.example.addressbook.entities.Linkman;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;


@Repository
public interface LinkmanRepository extends CrudRepository<Linkman, Long> {

    @Override
     public List<Linkman> findAll();

    @Query(nativeQuery = true,value = "SELECT A.Linkman_ID,NAME,sex,TEL,GROUP_NAME FROM LINKMAN A " +
            "LEFT JOIN GROUPING_LINKMAN  B ON A.Linkman_id=B.LINKMAN_ID " +
            "LEFT JOIN TEL C ON A.Linkman_ID=C.Tel_ID " +
            "LEFT JOIN GROUPING D ON D.GROUP_ID =B.GROUP_ID;")
    List<linkmanInfo> linkmanInfo();

    Linkman findById(long thID);

}
